package com.taotao.delayjob.core.mapper;


import com.github.pagehelper.Page;

import com.taotao.delayjob.core.model.RetryInst;
import com.taotao.delayjob.core.model.RetryInstPageData;
import com.taotao.delayjob.core.model.RetryInstPageParam;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
 * 任务重试实例DAO
 *
 * @author Fan Beibei
 * @date 2024-07-17 10:22:26
 */
@Mapper
public interface RetryInstMapper {

    RetryInst selectById(@Param("id") Long id);
    int batchInsert(Collection<RetryInst> list);

    /**
     * 查询待重试的任务
     *
     * @param maxNextTime
     * @return
     */
    List<RetryInst> selectForRetryInst(@Param("maxNextTime") Long maxNextTime);

    int updateRetryResult(@Param("id") Long id, @Param("status") String status,
                          @Param("note") String note,
                          @Param("nextTriggerTime") Long nextTriggerTime,
                          @Param("opTime") LocalDateTime opTime);

    int resetRetryNum(@Param("retryInstIds") Set<Long> retryInstIds, @Param("curNum") int curNum, @Param("nextTriggerTime") Long nextTriggerTime, @Param("opTime") LocalDateTime opTime);

    int updateNextTriggerTime(@Param("id") Long id,
                              @Param("nextTriggerTime") Long nextTriggerTime,
                              @Param("opTime") LocalDateTime opTime);


    Page<RetryInstPageData> queryPage(
            @Param("param") RetryInstPageParam param,
            @Param("pageNum") int pageNum,
            @Param("pageSize") int pageSize);

}